﻿using MediatR;
using Microsoft.VisualBasic;
using RedDragon.Common.Domain.produceplan;
using RedDragon.Common.Infrastructure.Interface;
using T.Common.Domain.Common;

namespace RedDragon.RBAC.API.Application.Common.produceplanW
{
    public class produceDetailsCreateHandler : IRequestHandler<produceDetailsCreateCommon, Result>
    {
        public readonly IBaseRepository<produceDetails> produceDetailsRepository;

        public produceDetailsCreateHandler(IBaseRepository<produceDetails> produceDetailsRepository)
        {
            this.produceDetailsRepository = produceDetailsRepository;
        }

        public async Task<Result> Handle(produceDetailsCreateCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = 0, Msg = "主生产计资源划新增失败" };
            try
            {
                var res = new produceDetails()
                {
                    ChooseId = request.ChooseId,
                    ChooseAttribute = request.ChooseAttribute,
                    Unit = request.Unit,
                    Specification = request.Specification,
                    BomVersion = request.BomVersion,
                    PlanCount = request.PlanCount,
                    StartDateTime = request.StartDateTime,
                    EndDateTime = request.EndDateTime,
                    produceplanNumber = request.produceplanNumber,
                    Remark = request.Remark
                };
                var res1 = await produceDetailsRepository.Add(res);
                if (res1 != 0)
                {
                    result.Code = 1;
                    result.Msg = "主生产计划资源新增成功";
                }



            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
